# -*- coding: utf-8 -*-

# $Id: errors.py 8 2012-09-02 01:35:34Z alexis.roda.villalonga@gmail.com $

class SkelError(Exception) :
    """Base exception.
    """
    pass

class UndefinedVarError(SkelError) :
    """Exception raised whenever a variable required by a template is
    missing from the context dictionary.

    The exception object has the following attributes:

    .. py:attribute:: filename

       path of the template that raised the exception.

    .. py:attribute:: varname

       name of the offending variable.
    """
    def __init__(self, varname, filename) :
        super(UndefinedVarError, self).__init__(varname)
        self.varname = varname
        self.filename = filename

    def __str__(self) :
        return "Variable '{var}' is not defined. File '{file}'".format(
            var=self.varname,
            file=self.filename
            )

class TemplateError(SkelError) :
    """Exception raised when an error is encountered in a template.

    The exception object has the following attributes:

    .. py:attribute:: filename

       path of the template that raised the exception.

    .. py:attribute:: message

       error message provided by the template engine.
    """
    def __init__(self, message, filename) :
        super(TemplateError, self).__init__(message)
        self.message = message
        self.filename = filename

    def __str__(self) :
        return "{message}. File '{file}'".format(
            message=self.message,
            file=self.filename
            )

